#include "game.h"
#include "display.c"
#include "btns.c"
#include "uart.c"
#include "timer.c"
int a;
int b;
a=1;
b=10;
void init_shape()
{
    update_timer_seed();
    game_shape.pos = timer_rand() % 4;
    game_shape.type = timer_rand() % 7;
    game_shape.shape = TETRIS_SHAPES[game_shape.type][game_shape.pos];
    update_timer_seed();
    game_shape.next_pos = timer_rand() % 4;
    game_shape.next_type = timer_rand() % 7;
    game_shape.next_shape = TETRIS_SHAPES[game_shape.next_type][game_shape.next_pos];
}

/**
 * 使用上下左右按钮控制方块的移动
 * 使用开始按钮，切换到下一个方块
 */
void main()
{
  unsigned char btn_code;
    uart_init();
    timer0_init();
    display_init();
    // display_speed_selection();

    init_shape();

    display_shape(1, 10, game_shape.shape);
    while (1)
    {
        btn_code = btn_scan();
        switch (btn_code)
        {
        case BTN_CODE_START:
            init_shape();
            display_shape(a,b, game_shape.shape);
            break;
        case BTN_CODE_UP:
            a=a-1;
            if(a<0)
            {
            a=0;
            }
            display_init();
            display_shape(a,b, game_shape.shape);
            break;
        case BTN_CODE_LEFT:
            b=b-1;
            display_init();
            display_shape(a,b, game_shape.shape);
            break;
        case BTN_CODE_RIGHT:
            b=b+1;
            display_init();
            display_shape(a,b,game_shape.shape);
            break;
        case BTN_CODE_DOWN:
            a=a+1;
            if(a>7)
            {
             a=7;
            }
            display_init();
            display_shape(a,b,game_shape.shape);
            break;
        default:
            break;
        }
    }
}